package com.t168.appinfo.controller.reception;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import sun.rmi.log.LogOutputStream;

import com.t168.appinfo.entity.DevUser;
import com.t168.appinfo.service.reception.devuser.DevUserService;


@Controller
@RequestMapping(value="/devUser")
public class DevUserController {

	@Resource(name = "devUserService")
	private DevUserService devUserService;

	public DevUserService getDevUserService() {
		return devUserService;
	}

	public void setDevUserService(DevUserService devUserService) {
		this.devUserService = devUserService;
	}


	/**
	 * 登录事件
	 * @param devCode
	 * @param devPassword
	 * @return
	 */
	@RequestMapping(value="/login",method = RequestMethod.POST)
	public String login(@RequestParam("devCode") String devCode,@RequestParam("devPassword") String devPassword,HttpSession session,HttpServletRequest request){
		
		DevUser devUser = devUserService.login(devCode, devPassword); 
		if(null != devUser){
			session.setAttribute("devUser", devUser);
			return "redirect:/devUser/main.html";
		}else{
			request.setAttribute("error", "用户名或密码不正确");
			return "jsp/devlogin";
		}
	}
	
	/**
	 * 注销登录
	 * @param session
	 */
	@RequestMapping(value="/logout",method = RequestMethod.GET)
	public String logout(HttpSession session){
		session.removeAttribute("devUser");
		return "redirect:/index.html";
	}
	
	/**
	 * 前台登录页面
	 * @return 页面地址
	 */
	@RequestMapping(value="/loginView.html")
	public String loginView(){
		return "jsp/devlogin";
	}

	
	/**
	 * 前台主页
	 * @return 前台主页的地址
	 */
	@RequestMapping(value = "/main.html")
	public String main(){
		return "jsp/developer/main";
	}
	
	
	/**
	 * 前台：APP信息页面
	 * @return APP信息页面的路径
	 */
	@RequestMapping(value = "/appinfolist.html")
	public String appInfoList(){
		return "jsp/developer/appinfolist";
	}
}
